#include <bits/stdc++.h>
using namespace std;
#define int long long

int n = 0,q = 0;
int arr[1000010] = {};

signed main() {
    int T = 0;
    cin >> T;
    while(T--) {
        cin >> n >> q;
        for(int i = 0;i < n; ++ i) {
            cin >> arr[i];
        }
        int ps = 0;
        for(int i = 0;i < q; ++ i) {
            int k,d;
            cin >> k >> d;
            ps += k % n;
            ps %= n;
            cout << arr[(ps + d) % n] << endl;
        }
    }
    return 0;
}

